<template>
  <div id="app">
    <h2>测试题</h2>
    <SubjectItem v-for="(item,index) in list" :key="index" :item="item" @resl="item.isCorrect = $event"></SubjectItem>

    <div>
      <FlagItem v-for="(item,index) in list" :key="index" :isCorrect="item.isCorrect" >{{index + 1}}.{{ result(item.isCorrect) }}</FlagItem>
    </div>
  </div>
</template>

<script>
import FlagItem from './components/FlagItem.vue';
import SubjectItem from './components/SubjectItem.vue';


export default {
  components:{
    SubjectItem,
    FlagItem
  },
  data() {
    return{
      list:[],
    }
  },
  methods:{
    result(state) {
      if (state === null) {
        return '未完成'
      } else if (state) {
        return '回答正确'
      } else {
        return '回答错误'
      }      
    }
  },
  created() {
    for(let i = 0;i < 5 ;i++) {
      this.list.push({
        firstNum:Math.floor(Math.random() * 10),
        secondNum:Math.floor(Math.random() * 10),
        isCorrect:null
      })
    }
  },
  updated() {
    console.log(this.list);
    
  }
};
</script>

<style>
body {
  background-color: #eee;
}

#app {
  background-color: #fff;
  width: 500px;
  margin: 50px auto;
  box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
  padding: 2em;
}
</style>